package cn.tedu.ivos.dictoption.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.dictoption.pojo.dto.DictoptionQuery;
import cn.tedu.ivos.dictoption.pojo.dto.DictoptionSaveParam;
import cn.tedu.ivos.dictoption.pojo.vo.DictoptionVO;
import cn.tedu.ivos.dictoption.service.DictoptionService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Tag(name="字典项模块")
@RequestMapping("/v1/dictOption")
@RestController
public class DictoptionController {

    @Autowired
    DictoptionService dictoptionService;

    @GetMapping("select")
    @Operation(summary = "查询字典项")
    @ApiOperationSupport(order = 10)
    public JsonResult selectDictoption(DictoptionQuery query){
        log.debug("查询字典项："+query);
        List<DictoptionVO> list=dictoptionService.selectDictoption(query);
        return JsonResult.ok(list);
    }

   @PostMapping("save")
   @Operation(summary = "新增字典项")
   @ApiOperationSupport(order = 20)
   public JsonResult saveDictoption(DictoptionSaveParam param){
        log.debug("新增字典项："+param);
        dictoptionService.saveDictoption(param);
        return JsonResult.ok();

   }

    @PostMapping("delete")
    @Operation(summary = "删除字典项")
    @ApiOperationSupport(order = 30)
    public JsonResult deleteDictoption(Long id){
        log.debug("删除字典项："+id);
        dictoptionService.deleteDictoption(id);
        return JsonResult.ok();
    }


    /*定义一个根据字典code查其对应所有字典项的方法*/
    @GetMapping("select/{code}")
    @Operation(summary = "根据字典编码查询所有的字典项")
    @ApiOperationSupport(order = 40)
    public JsonResult selectCode(@PathVariable String code){
        log.debug("查询字典项："+code);
        List<DictoptionVO> list =dictoptionService.selectCode(code);
        return JsonResult.ok(list);
    }


}
